<?php

/**
 * This is the model class for table "poll".
 *
 * The followings are the available columns in table 'poll':
 * @property string $id
 * @property integer $tid
 * @property string $nid
 * @property string $uid
 * @property string $description
 * @property integer $status
 * @property integer $start_time
 * @property integer $finish_time
 * @property string $value
 */
class Poll extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Poll the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'poll';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('tid, nid, uid, description, status, start_time, finish_time, value', 'required'),
			array('tid, status', 'numerical', 'integerOnly'=>true),
			array('nid, uid', 'length', 'max'=>10),
			array('value', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, tid, nid, uid, description, status, start_time, finish_time, value', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				'node'=>array(self::BELONGS_TO, 'Node', 'nid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'tid' => '类型',
			'nid' => '名称',
			'uid' => '用户',
			'description' => '申请理由',
			'status' => '状态',
			'start_time' => '开始时间',
			'finish_time' => '结束时间',
			'value' => '投票选值',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('tid',$this->tid);
		$criteria->compare('nid',$this->nid,true);
		$criteria->compare('uid',$this->uid,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('start_time',$this->start_time);
		$criteria->compare('finish_time',$this->finish_time);
		$criteria->compare('value',$this->value,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}